﻿using System.Xml;
using CSLauncher.Commands;
using CSLauncher.Configuration.Interface;

namespace CSLauncher.Configuration.Xml
{
    internal abstract class Item : IItem
    {
        protected XmlNode Node { get; private set; }

        public static IItem Create(XmlNode node, SubMenu parentMenu)
        {
            if (node.Name.Equals("SubMenu"))
            {
                return new SubMenu(node, parentMenu);
            }
            else if (node.Name.Equals("RunApplication"))
            {
                return new RunApplication(node.Attributes["name"].Value, node.Attributes["location"].Value, node.Attributes["arguments"].Value);
            }

            throw new UnknownNodeException(node);
        }

        protected Item (XmlNode node)
        {
            Node = node;
        }

        public string Name
        {
            get { return Node.Attributes["name"].Value; }
        }
    }
}
